extends layout

block meta
    link(rel="stylesheet", href="#{options.cdn_path}/js/artDialog/skins/combo?/js/artDialog/skins/default.css&v=#{options.site_version}")

block content
    .navbar
        .navbar-inner
            a.brand(href="/")
                span.first #{options.site_name}
    .row-fluid
        .dialog
            .block
                p.block-heading 登录
                    a.pull-right(href="/api/qq", title="qq快速登录", style="height: 34px;margin-right: 10px;")
                        img(src="#{options.cdn_path}/images/qq_s.png?v=#{options.site_version}")
                    a.pull-right(href="/api/baidu", title="百度帐号登录", style="height: 34px;")
                        img(src="#{options.cdn_path}/images/login-baidu.png?v=#{options.site_version}")
                .block-body
                    form(action="/admin/session", method="post")
                        label 邮箱帐号：
                        input.span12(type="email", name="email", required="required", original-title="请输入您的常用邮箱！")
                        label 密码：
                        input.span12(type="password", name="pwd", required="required", original-title="请输入您的密码！")
                        input.btn.btn-primary.pull-right(type="submit", value="登录")
                        label.remember-me
                            input(type="checkbox", name="remember", value="1", original-title="有效期一个月！")
                            | &nbsp;记住密码
                        .clearfix
            p.pull-right
                a.forgot(href="#") 忘了密码？

block script
    script(src="#{options.cdn_path}/js/artDialog/jquery.artDialog.min.js?v=#{options.site_version}")
    script
        $(function(){
            $('form').submit(function(){
                var dialog = $.dialog();
                _post(this, dialog, function(data){
                    if(data.status === 0) {
                        dialog.content('登录成功！').lock().time(1000);
                        setTimeout(function(){
                            location.reload();
                        }, 1000);
                    } else {
                        dialog.content('登录失败，请检查用户名和密码！').lock().time(2000);
                    }
                });
                return false;
            });
            $('.forgot').click(function(){
                var dialog = $.dialog({
                    title: '请输入邮箱地址：',
                    content: '<input id="reset-pwd" name="email" style="width:15em; padding:4px"/>',
                    lock: true,
                    ok: function () {
                        var input = $('#reset-pwd');
                        var email = $.trim(input.val());
                        if (!/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/.test(email)) {
                            input.select();
                            input.focus();
                            return false;
                        } else {
                            var ajaxDialog = $.dialog({fixed: true, lock: true});
                            $.post('/reset_pwd', {email: email}, function(data){
                                if(data.status){
                                    ajaxDialog.title('邮件发送成功！');
                                    ajaxDialog.content('请登录邮箱按指示完成密码重置操作！').lock().time(2000);
                                } else {
                                    ajaxDialog.title('提示！');
                                    ajaxDialog.content('邮件发送失败，请稍后重试！').lock().time(2000);
                                }
                            });
                        };
                    },
                    cancel: true
                });
                return false;
            });
        })